
local jiguo = fk.CreateSkill {
  name = "lingling__jiguo",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["lingling__jiguo"] = "岌国",
  [":lingling__jiguo"] = "锁定技，回合结束时，你失去1点体力或减1点体力上限。当一名角色每回合首次失去体力或体力上限减少后，你与其各摸一张牌。",
}

jiguo:addEffect(fk.TurnEnd, {
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(jiguo.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askToChoice(player, {
      choices = {"loseMaxHp", "loseHp"},
      skill_name = jiguo.name,
    })
    if choice == "loseMaxHp" then
      room:changeMaxHp(player, -1)
    else
      room:loseHp(player, 1, jiguo.name)
    end
  end,
})

jiguo:addEffect(fk.HpLost, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(jiguo.name) and
      #player.room.logic:getEventsOfScope(GameEvent.LoseHp, 2, function (e)
        return e.data.who == target
      end, Player.HistoryTurn) == 1
  end,
  on_use = function (self, event, target, player, data)
    player:drawCards(1, jiguo.name)
    if not target.dead then
      target:drawCards(1, jiguo.name)
    end
  end,
})

jiguo:addEffect(fk.MaxHpChanged,{
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(jiguo.name) and
      #player.room.logic:getEventsOfScope(GameEvent.ChangeMaxHp, 2, function (e)
        return e.data.who == target and e.data.num < 0
      end, Player.HistoryTurn) == 1 and data.num < 0
  end,
  on_use = function (self, event, target, player, data)
    player:drawCards(1, jiguo.name)
    if not target.dead then
      target:drawCards(1, jiguo.name)
    end
  end,
})

return jiguo
